package com.aote.expression.paramprocessor;

import java.util.Map;

import com.aote.expression.Param;
import com.browsesoft.htmlcomponent.HTMLBasicComponent;
import com.browsesoft.resource.Resource;
import com.browsesoft.user.User;

/*
 * 登录用户属性默认值处理器
 * 可以得到登录用户及登录用户父资源得某个属性
 */
public class LoginUserAttrProcessor implements ParamProcessor {

	public String process(Param param, Map attribures, User loginUser,
			HTMLBasicComponent component) {
		String result = "";
		Map map = param.getParams();
		if (map.get("parentattrname") != null) {
			String attrName = (String) map.get("parentattrname");
			Resource parent = loginUser.getParent();
			result = (String) parent.getAttributes().get(attrName);
		} else {
			String attrName = (String) map.get("attrname");
			result = (String) loginUser.getAttributes().get(attrName);
		}
		// 如果无值，抛异常
		if (result == null) {
			throw new NoFitValueException(param);
		} else {
			return result;
		}
	}
}
